//
//  CellForSearch.m
//  MY Project For Sport
//
//  Created by admin on 16/2/14.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "CellForSearch.h"
#import "ModelForSearch.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <DKNightVersion.h>

@interface CellForSearch ()

@property (nonatomic, retain) UIImageView *image;
@property (nonatomic, retain) UILabel *labelForMadie;
@property (nonatomic, retain) UILabel *labelFordate;

@end


@implementation CellForSearch

-(void)dealloc {
    

    [_image release];
    [_labelFordate release];
    [_labelForMadie release];
    [_labelForTitle release];
    [super dealloc];

    
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {


    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);

        [self createSubView];
        
    }
    
    
    return self;


}


- (void)createSubView {

    self.image = [[UIImageView alloc] init];
    [self.contentView addSubview:self.image];
    [_image release];
    
    
    self.labelFordate = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelFordate];
    [_labelFordate release];
    
    
    self.labelForMadie = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForMadie];
    [_labelForMadie release];
    
    
    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
 

    
    
}

-(void)layoutSubviews {


    [super layoutSubviews];
    
    
   self.image.frame = CGRectMake(5, 5, self.contentView.frame.size.width / 4, self.contentView.frame.size.height - 10);
    //self.image.backgroundColor = [UIColor redColor];
    
    self.labelForTitle.numberOfLines = 0;
    self.labelForTitle.font = [UIFont systemFontOfSize:16];
    self.labelForTitle.frame = CGRectMake(self.contentView.frame.size.width / 4 + 10, 10, self.contentView.frame.size.width - self.contentView.frame.size.width / 4 - 10 - 5 , (self.contentView.frame.size.height - 20) / 3 * 2);
    //self.labelForTitle.backgroundColor = [UIColor redColor];
   // self.labelForTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);


    self.labelForMadie.frame = CGRectMake(self.contentView.frame.size.width / 4 + 10, (self.contentView.frame.size.height - 20) / 3 * 2 + 15, self.contentView.frame.size.width / 6, self.contentView.frame.size.height / 3 - 10);
    self.labelForMadie.textColor = [UIColor grayColor];
    self.labelForMadie.font = [UIFont systemFontOfSize:10];
    //self.labelForMadie.backgroundColor = [UIColor redColor];
    
    self.labelFordate.frame = CGRectMake(self.contentView.frame.size.width / 7 * 6, (self.contentView.frame.size.height - 20) / 3 * 2 + 15, self.contentView.frame.size.width /  7 - 10 , self.contentView.frame.size.height / 3 - 10);
    self.labelFordate.textColor = [UIColor grayColor];
    self.labelFordate.font = [UIFont systemFontOfSize:10];
   // self.labelFordate.backgroundColor = [UIColor orangeColor];
    

}


-(void)passModelForSearch:(ModelForSearch *)model {

    
    
    [self.image sd_setImageWithURL:[NSURL URLWithString:model.imgurl]];
    
    
    self.labelForTitle.text = model.origin_title;
    
    self.labelForMadie.text = model.media;
    
    NSRange range = {5,5};
    self.labelFordate.text = [model.datetime substringWithRange:range];




}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
